<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0">
    <title>条形码预览</title>
    <script src="../../lib/axios-0.18.0.js"></script>
    <script src="../../http/request.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            width: 100%;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .bar-code-box {
            width: 90vw;
            transition: all 1s ease-in-out;
        }

        .bar-code {
            width: 90vw;
            transition: all 1s ease-in-out;
        }

        .rotate {
            width: 90vh;
            transform: rotate(90deg);
        }

        .bar-code--scale {
            width: 90vh;
        }

        .description {
            font-size: 14px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="bar-code-box rotate">
        <!-- 测试用例 -->
        <img class="bar-code bar-code--scale"
            src=""
            alt="">
    </div>
</body>
<script>
    const barCode = document.querySelector('.bar-code')
    const dppToken = localStorage.getItem('dppToken')
    // 二次跳转处理
    const token = getQueryString('token')
    if (token) {
        localStorage.setItem('dppToken', token)
    }
    // 请求
    if (!dppToken) {
        location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx576478355cd34bb0&redirect_uri=http%3A%2F%2Ftinycnc.cn%2Fuser%2Fhome%2FJTQR&response_type=code&scope=snsapi_userinfo&state=1&connect_redirect=1#wechat_redirect'
    } else {
        getBarCode()
    }
    async function getBarCode() {
        const res = await axios.get('/user/home/rabbitQR')
        if (res.code === 1) {
            barCode.src = 'data:image/png;base64,' + res.data.rabbitQR
        } else {
            location.href = '../../personalCenter.html?flag=1'
        }
    }
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
        var r = window.location.search.substring(1).match(reg)
        if (r != null) {
            return decodeURIComponent(r[2])
        }
        return ''
    }
</script>

</html>